<?php
/* 
* @Title:  [购物车模型]
* @Author: {chenlei} [chenleib5@126.com]
* @Date:   2014-04-15 17:36:04
* @Last Modified by:   Administrator
* @Last Modified time: 2014-04-18 16:14:51
* @Copyright:  [hn7m.com]
*/
class CartModel extends Model{
	public $table='cart';
	/**
	 * [add_data 将购物车session中的数据存到数据库]
	 * @param [type] $data [description]
	 */
	public function add_data($sessionData,$uid){
		foreach ($sessionData['goods'] as $key => $value) {
			$data=array(
				'sname'			=>$value['name'],
				'snum'			=>$value['num'],
				'sprice'		=>$value['price'],
				'splace'		=>$value['place'],
				'scate'			=>$value['cate'],
				'simg_url'		=>$value['imgUrl'],
				'soptions'		=>implode(',', $value['options']),
				'sinventory'	=>$value['kucun'],
				'stotal'		=>$value['total'],
				'session_id'	=>$key,
				'qm_combine_bid'=>$value['bid'],
				'qm_goods_gid'	=>$value['id'],
				'qm_user_uid'	=>$uid
				);
			$this->add($data);
		}
	}
	/**
	 * [get_data 获得所有的数据]
	 * @return [type] [description]
	 */
	public function get_data($where=NULL){
		return $this->where($where)->findAll();
	}
	/**
	 * [get_total_rows 求和]
	 * @return [type] [description]
	 */
	public function get_total($field,$where=NULL){
		return $this->where($where)->sum($field);
	}
	/**
	 * [del_data 按登陆用户的uid删除数据]
	 * @param  [type] $uid [description]
	 * @return [type]      [description]
	 */
	public function del_data($uid){
		return $this->where(array('qm_user_uid'=>$uid))->del();
	}
}
?>